package com.android.qjpmc.widget.service;

import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import androidx.annotation.RequiresApi;

import com.android.qjpmc.widget.manager.JobServiceSchedulerManager;


/**
 * Created by Administrator on 2019/6/24.
 */

@RequiresApi(api = Build.VERSION_CODES.N)
public abstract class BaseJobService extends JobService {

    public final long requestInterval = 15 * 60 * 1000;//间隔多久调用一次
    private Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        this.mContext = this;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
       // Logger.d(getJobClaszz().getName() + "==onStartCommand");
        return START_NOT_STICKY;
    }

    @Override
    public boolean onStartJob(final JobParameters jobParameters) {
      //  Logger.d(getJobClaszz().getName() + "==onStartJob");
        handlerMethod(jobParameters);
        return true;
    }

    protected abstract void handlerMethod(JobParameters jobParameters);

    @Override
    public boolean onStopJob(JobParameters jobParameters) {
      //  Logger.d(getJobClaszz().getName() + "==onStopJob");
        return false;
    }


    public JobInfo getJobInfo() {

        return JobServiceSchedulerManager.getInstance().getJobInfo(this, getJobId(), getJobClaszz(), getRequestInterval());
    }

    protected abstract Class<?> getJobClaszz();

    public abstract int getJobId();

    public long getRequestInterval() {
        return requestInterval;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
}

